﻿using System;

namespace Calculator
{
    [ImportClass("", "Math")]
    public static class MathEx
    {
        public static double Lg(double x)
        {
            return Math.Log(x) / Math.Log(10);
        }

        public static double Ln(double x)
        {
            return Math.Log(x);
        }

        public static long Fac(long x)
        {
            var p = 1;
            for (var i = 2; i <= x; i++)
            {
                p *= i;
            }
            return p;
        }

        public static double Reciprocal(double x)
        {
            return 1 / x;
        }

        public static double Sqr(double x)
        {
            return x * x;
        }

        public static double Cbrt(double x)
        {
            return Math.Pow(x, 1 / 3);
        }

        public static double Pow2n(double x)
        {
            return Math.Pow(2, x);
        }

        public static double Sinh(double x)
        {
            return (Math.Exp(x) - Math.Exp(-x)) / 2;
        }

        public static double Cosh(double x)
        {
            return (Math.Exp(x) + Math.Exp(-x)) / 2;
        }

        public static double Tanh(double x)
        {
            return (Math.Exp(x) - Math.Exp(-x)) / (Math.Exp(x) + Math.Exp(-x));
        }

        public static double Asinh(double x)
        {
            return Math.Log(x + Math.Sqrt(x * x + 1));
        }

        public static double Acosh(double x)
        {
            return Math.Log(x + Math.Sqrt(x * x - 1));
        }

        public static double Atanh(double x)
        {
            return Math.Log((1 + x) / (1 - x)) / 2;
        }
    }
}
